{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2025"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import math\n",
    "\n",
    "import matplotlib as mpl\n",
    "from matplotlib import pyplot as plt\n",
    "from matplotlib import cm\n",
    "\n",
    "# Load data\n",
    "results = np.loadtxt(\"../data/experiments/compare_results_360fov_apartment.txt\")                     # idA,idB,\n",
    "results = np.array([results]).T                                                     # fov_overlap, octree_overlap\n",
    "                                                                                    # alignability, alignment_risk\n",
    "                                                                                    # degeneracy, ICN\n",
    "results.shape[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Fill overlap matrix\n",
    "def samplemat(dims, column_id):\n",
    "    matrix = np.zeros(dims)\n",
    "    line_count = 0\n",
    "    for i in range(min(dims)):\n",
    "        for j in range(min(dims)):\n",
    "            if (results[0][line_count]==i and results[1][line_count]==j):\n",
    "                matrix[i, j] = results[column_id][line_count]\n",
    "                line_count=line_count+1\n",
    "    return matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "################################\n",
    "# Plot octree-overlap matrix\n",
    "################################\n",
    "fig = plt.figure()\n",
    "ax = fig.add_subplot(111)\n",
    "cmap = cm.get_cmap('jet')\n",
    "\n",
    "ax.set_xlabel('Cloud A')\n",
    "ax.set_ylabel('Cloud B')\n",
    "ax.xaxis.set_label_position('top')\n",
    "\n",
    "# Display matrix\n",
    "mat_size = int(math.sqrt(results.shape[1]))\n",
    "# pass octree-overlap column to be taken from results\n",
    "cax = ax.matshow(samplemat((mat_size, mat_size), 3), cmap=cmap)\n",
    "ax.text(23, 47, 'Apartment Dataset, Estimated Overlap', color='black', horizontalalignment='center',\n",
    "         fontsize=15)\n",
    "# ax.text(15, 32, 'Stairs Dataset, Estimated Overlap', color='black', horizontalalignment='center',\n",
    "#          fontsize=15)\n",
    "\n",
    "# extract all colors\n",
    "cmaplist = [cmap(i) for i in range(cmap.N)]\n",
    "# create the new map\n",
    "cmap = cmap.from_list('pred_cmap', cmaplist, cmap.N)\n",
    "# define the bins and normalize\n",
    "bounds = np.linspace(0,100,21)\n",
    "norm = mpl.colors.BoundaryNorm(bounds, cmap.N)\n",
    "# create a second axes for the colorbar\n",
    "ax2 = fig.add_axes([0.83, 0.1, 0.03, 0.8])\n",
    "cb = mpl.colorbar.ColorbarBase(ax2, cmap=cmap, norm=norm, spacing='proportional', ticks=bounds, boundaries=bounds)\n",
    "ax2.set_ylabel('Octree-based Overlap [%]')\n",
    "\n",
    "################################\n",
    "# Plot fov-overlap matrix\n",
    "################################\n",
    "fig2 = plt.figure()\n",
    "ax3 = fig2.add_subplot(111)\n",
    "cmap = cm.get_cmap('jet')\n",
    "\n",
    "ax3.set_xlabel('Cloud A')\n",
    "ax3.set_ylabel('Cloud B')\n",
    "ax3.xaxis.set_label_position('top')\n",
    "\n",
    "# Display matrix\n",
    "mat_size = int(math.sqrt(results.shape[1]))\n",
    "# pass fov-overlap column to be taken from results\n",
    "cax = ax3.matshow(samplemat((mat_size, mat_size), 2), cmap=cmap)\n",
    "ax3.text(23, 47, 'Apartment Dataset, Estimated Overlap', color='black', horizontalalignment='center',\n",
    "         fontsize=15)\n",
    "# ax3.text(15, 32, 'Stairs Dataset, Estimated Overlap', color='black', horizontalalignment='center',\n",
    "#          fontsize=15)\n",
    "\n",
    "# extract all colors\n",
    "cmaplist = [cmap(i) for i in range(cmap.N)]\n",
    "# create the new map\n",
    "cmap = cmap.from_list('pred_cmap', cmaplist, cmap.N)\n",
    "# define the bins and normalize\n",
    "bounds = np.linspace(0,100,21)\n",
    "norm = mpl.colors.BoundaryNorm(bounds, cmap.N)\n",
    "# create a second axes for the colorbar\n",
    "ax4 = fig2.add_axes([0.83, 0.1, 0.03, 0.8])\n",
    "cb = mpl.colorbar.ColorbarBase(ax4, cmap=cmap, norm=norm, spacing='proportional', ticks=bounds, boundaries=bounds)\n",
    "ax4.set_ylabel('FOV-based Overlap [%]')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
